package com.qixin.web.controller.User;

import com.qixin.api.bean.ComChargeInfo;
import com.qixin.api.bean.ComPtUser;
import com.qixin.api.service.ComCarChargeService;
import com.qixin.api.service.ComChargeInfoService;
import com.qixin.api.service.ComPtUserService;
import com.qixin.web.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Zhang on 2018/11/7.
 * 用户个人中心
 */
@Controller
@RequestMapping("/UserCent")
public class UserCentController {
    @Autowired
    ComChargeInfoService comChargeInfoService;
    @Autowired
    ComPtUserService comPtUserService;
    @Autowired
    ComCarChargeService comCarChargeService;

    //个人中心--我的订单
    @RequestMapping("/MyOrder.html")
    public String MyOrder(HttpSession session, Model model) {
        Long userId = SessionUtil.getUserId(session);
        Map map = new HashMap<>();
        map.put("user_id", userId);
        List<ComChargeInfo> comChargeInfos = comChargeInfoService.selectByMap(map);
        model.addAttribute("orders", comChargeInfos);
        return "/System/MyOrder";
    }

    //个人中心--我的信息

    @RequestMapping("/MyInfo.html")
    public String MyInfo(HttpSession session, Model model) {
        Long userId = SessionUtil.getUserId(session);
        int flag = SessionUtil.getUserFlag(session);
        if (flag == 1) {
            ComPtUser comPtUser = comPtUserService.findUserInfoByPtUserIdForWeChart(userId);
            model.addAttribute("userInfo", comPtUser);
        } else {
            ComPtUser comPtUser = comPtUserService.findUserInfoByUserIdForWeChart(userId);
            model.addAttribute("userInfo", comPtUser);
        }
        return "/System/UserMation";
    }
    //个人中心--我的车辆

    @RequestMapping("/MyCar.html")
    public String MyCar(HttpSession session, Model model) {
        Long userId = SessionUtil.getUserId(session);
        int flag = SessionUtil.getUserFlag(session);
        if (flag == 1) {
            Map map = new HashMap<>();
            map.put("relacation_id",userId);
            model.addAttribute("car", comCarChargeService.selectByMap(map));
        } else {
            model.addAttribute("car", comCarChargeService.MyCar(userId));
        }
        return "/System/MyCar";
    }
	@RequestMapping("/wsz.html")
	public String wsz(){
    	return "/System/wsz";
	}

}
